<?php #20070423
define('APPPERSONALPAGE','1.00');
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/


/* Personal Page */

// carica libemoticons e libBBcode se sono presenti
if (file_exists("extras/bbcode/libBBcode.inc")&& !defined('LIBBBCODE'))
    include "extras/bbcode/libBBcode.inc";
if (file_exists("extras/emoticons/libEmoticons.inc")&& !defined('LIBEMOTICONS') )
    include "extras/emoticons/libEmoticons.inc";


//il post dela pagina scelta
$userpage=$_REQUEST['userpage'];


/* solo il proprietario della pagina la puo' modificare */
$save=$_POST['save'];
if ($save=="datas/$path/$apptitle/".user_getuser()."/pagina"){
    $userpage=user_getuser();
    $datas=stripslashes($_POST['editor']);
    if (defined('LIBBBCODE'))$datas=bb2html($datas);
    if (defined('LIBEMOTICONS'))$datas=emoticons2html($datas);

    if($save!=""){
    $fp=fopen($save,"w");
    fwrite($fp,$datas);
    fclose($fp);
    }
}
/*******************************************************************************/
?>

<?php structure_openBlock("table appl",apptitle($appname),""); ?>
<p>
<style>
h3
{
	margin: 0;
	font-size: 14px;
}

</style>
<form name='seluser' action="index.php?appname=<?=$appname?>" method="post" >
<select name="userpage">
<!--<option><?=$userpage?></option>-->
<?php
    $listuser=user_listusers();
    $i=0;
    foreach($listuser as $userselect){
	if ($userselect==$userpage)
	    $def=$i;
	echo"<option>$userselect</option>";
	$i++;
    }
    echo "<script>document.seluser.userpage.selectedIndex='$def';</script>";
?>

</select>
<input type='submit' value="vedi" />
</form>
<?php
/*crea la pagina di default ****************************************************/
if ($userpage!=""){
    // non sono dati riservati e vengono scritti fuori da sb nella cartella con nome $apptitle
    if (!file_exists("datas/$path/$apptitle"))mkdir("datas/$path/$apptitle",0755);
    if (!file_exists("datas/$path/$apptitle/$userpage"))mkdir("datas/$path/$apptitle/$userpage",0755);
    if (!file_exists("datas/$path/$apptitle/$userpage/images"))mkdir("datas/$path/$apptitle/$userpage/images",0755);


    if (!file_exists("datas/$path/$apptitle/$userpage/pagina")){
        $fp=fopen("datas/$path/$apptitle/$userpage/pagina","w");
	//Scrive il file attenzione i path devono essere assoluti per compatibilita' con FCKeditor
	fwrite($fp,str_replace("_user_",$userpage, @join(@file("$path/$appname/default"))));
	fclose($fp);
    }
}
else{
?>
    <h2> le pagine degli utenti </h2>
<?php
    if (count($listuser)){
	foreach($listuser as $userselect){
	    echo"<a href='index.php?appname=$appname&userpage=$userselect'>$userselect</a><br />\n";
	}
    }
}
/*******************************************************************************/
?>
<?php echo @join(@file("datas/$path/$apptitle/$userpage/pagina")); ?>
</p>
<?php if ((user_getuser()==$userpage && $userpage!="")  || admin_verifyIP() ){ ?>
<h3 class='edit'><a href="<?=ahah_link("index.php?appname=_editor.inc&appdest=".$_GET['appname']."&file=datas/$path/$apptitle/$userpage/pagina",$path,"center");?>">edit</a></h3>
<?php } ?>
<?php structure_closeBlock(); ?>

